$(function(){
    var vCodes=1;
    // 通过接口获取验证码
    $('.getCode').on('click',function(){
        $.ajax({
                url:'/user/vCode',
                type:'get',
                success:function(res){
                    alert("验证码为:"+res.vCode);
                    vCodes = res.vCode;
                }
            });
    });
    // 获取用户的注册信息
	$('#registerBtn').on('click',function(){
        var username=$('[name="username"]').val();
        var mobile = $('[name="mobile"]').val();
        var password=$('[name="password"]').val();
        var againPass=$('[name="againPass"]').val();
        var vCode = $('[name="vCode"]').val();  
        //验证输入框中的信息是否填入正确 username.indexOf(" ")!=-1  ->代表有空格
        if(!username || username.indexOf(" ")!=-1){
            mui.toast("请输入正确的用户名");
           
        } 
         if(!mobile || mobile.length<11){
         	mui.toast("请输入正确的电话号码，（11位）");
            return;
           
        } 
         if(!password || password.indexOf(" ")!=-1){
         	mui.toast("请输入正确的密码");
            return;
           
        } 
        if(againPass!=password || againPass.indexOf(" ")!=-1){
        	mui.toast("请输入正确的确定密码");
            return;
           
        } 
         if(vCode!=vCodes || vCode.indexOf(" ")!=-1){
         	mui.toast("请输入正确的验证码");
            return;
        }
        $.ajax({
            url:'/user/register',
            type:'post',
            data:{
                username:username,
                password:password,
                mobile:mobile,
                
            },
            success:function(res){
                if(res.success){
                	mui.toast("注册成功");
                	setTimeout(function(){
                		location.href('login.html');
                	},1000);
                	
                }else{
                	console.log(res);
                }
            }
        });

    });
   
   
    
    
})
